import Static_Data from '@/data/index'
import moment from 'moment'
moment.locale('zh-cn')

const mncCityKVParse = Static_Data.mnc_city.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  if (cur.children && cur.children.length > 0) {
    cur.children.map(function(subitem) {
      acc[subitem.id] = subitem.label
    })
  }
  return acc
}, {})

const cityKVParse = Static_Data.city.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  if (cur.children && cur.children.length > 0) {
    cur.children.map(function(subitem) {
      acc[subitem.id] = subitem.label
    })
  }
  return acc
}, {})

const industryKVParse = Static_Data.industry.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  return acc
}, {})

const mncIndustryKVParse = Static_Data.mnc_industry.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  return acc
}, {})

const mncJobKVParse = Static_Data.mnc_job.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  if (cur.children && cur.children.length > 0) {
    cur.children.map(function(subitem) {
      acc[subitem.id] = subitem.label
    })
  }
  return acc
}, {})

const jobKVParse = Static_Data.job.reduce((acc, cur) => {
  acc[cur.id] = cur.label
  if (cur.children && cur.children.length > 0) {
    cur.children.map(function(subitem) {
      acc[subitem.id] = subitem.label
    })
  }
  return acc
}, {})

const companyTypeKVParse = Static_Data.company_type.reduce((acc, cur) => {
  if (cur.id && cur.id !== '') {
    acc[cur.id] = cur.label
  }
  return acc
}, {})
const languageLevelKVParse = Static_Data.language_level.reduce((acc, cur) => {
  if (cur.id && cur.id !== '') {
    acc[cur.id] = cur.label
  }
  return acc
}, {})

const educationBackgroudKVParse = Static_Data.education_backgroud.reduce((acc, cur) => {
  if (cur.id && cur.id !== '') {
    acc[cur.id] = cur.label
  }
  return acc
}, {})

const userStatusKVParse = Static_Data.userStatus.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const genderKVParse = Static_Data.gender.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const bulletinStatusParse = Static_Data.bulletin_status.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const targetTypeParse = Static_Data.target_type.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const ishandleParse = Static_Data.is_handel_options.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const listFolderKVParse = Static_Data.list_folder.reduce((acc, cur) => {
  acc[cur.id] = cur.name
  return acc
}, {})
const contactPeopleDegreeKVParse = Static_Data.contact_people_degree.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const guaranteePeriodKVParse = Static_Data.guarantee_period.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const projectStatusKVParse = Static_Data.project_status.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const projectPriorityKVParse = Static_Data.project_priority.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const projectRoleKVParse = Static_Data.project_role.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const officeKVParse = Static_Data.office.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const cvStatusKVParse = Static_Data.cv_status.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const invoiceStatusKVParse = Static_Data.invoice_status.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

const feeTypeParse = Static_Data.fee_type.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const invoiceTypeParse = Static_Data.invoice_type.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})
const marriageKVParse = Static_Data.marriage.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

export function marriageFilter(id) {
  return marriageKVParse[id]
}
export function languageLevelFilter(id) {
  return languageLevelKVParse[id]
}
export function educationBackgroudFilter(id) {
  return educationBackgroudKVParse[id]
}

export function listFolderValFilter(id) {
  return listFolderKVParse[id]
}
export function officeValFilter(id) {
  return officeKVParse[id]
}
export function cvStatusValFilter(id) {
  return cvStatusKVParse[id]
}
export function guaranteePeriodValFilter(id) {
  return guaranteePeriodKVParse[id]
}

export function mncCityValFilter(id) {
  const value = mncCityKVParse[id]
  if (value && value !== '') {
    return value
  } else {
    return id
  }
}
export function cityValFilter(id) {
  return cityKVParse[id]
}
export function jobFilter(id) {
  return jobKVParse[id]
}
export function mncJobFilter(id) {
  return mncJobKVParse[id]
}
export function industryFilter(id) {
  return industryKVParse[id]
}
export function mncIndustryFilter(id) {
  return mncIndustryKVParse[id]
}

export function companyTypeFilter(id) {
  return companyTypeKVParse[id]
}
export function userStatusFilter(id) {
  return userStatusKVParse[id]
}
export function genderFilter(id) {
  return genderKVParse[id]
}
export function bulletinStatusFilter(id) {
  return bulletinStatusParse[id]
}
export function targetTypeFilter(id) {
  return targetTypeParse[id]
}
export function ishandleFilter(id) {
  return ishandleParse[id]
}
export function contactPeopleDegreeFilter(id) {
  return contactPeopleDegreeKVParse[id]
}
export function projectStatusFilter(id) {
  return projectStatusKVParse[id]
}
export function projectPriorityFilter(id) {
  return projectPriorityKVParse[id]
}
export function projectRoleFilter(id) {
  return projectRoleKVParse[id]
}
export function feeTypeFilter(id) {
  return feeTypeParse[id]
}
export function invoiceTypeFilter(id) {
  return invoiceTypeParse[id]
}
export function invoiceStatusFilter(id) {
  return invoiceStatusKVParse[id]
}
export function timeFromNowFilter(timestamp) {
  if (timestamp) {
    return moment(Number(timestamp)).fromNow()
  } else {
    return ''
  }
}
export function timeFilter(time, cFormat) {
  if (arguments.length === 0) {
    return null
  }

  if ((time + '').length === 10) {
    time = +time * 1000
  }

  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    date = new Date(parseInt(time))
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
    let value = formatObj[key]
    if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
    if (result.length > 0 && value < 10) {
      value = '0' + value
    }
    return value || 0
  })
  return time_str
}

